package cyy.example.com.facotry.model.api;

import com.example.com.common.utils.TimeUtils;
import com.google.gson.Gson;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import cyy.example.com.facotry.model.api.response.HistoryDataEntity;


/**
 * Created by ChenYiYao on 2018/7/3.
 */
public class EntityText {

    public static void main(String[] srt) {
        BaseEntity<HistoryDataEntity> baseEntit = new BaseEntity<>();
        HistoryDataEntity entity = new HistoryDataEntity();
        baseEntit.code = "0000";
        baseEntit.msg = "成功";
        baseEntit.setData(entity);
//        entity.setRegionCode("00001");
//        entity.setSiteCode("101");
//
//        RealDataEntity.ParamObjectListBean rPBean = new RealDataEntity.ParamObjectListBean();
//        rPBean.setParamCode("总氮");
//        rPBean.setStandardValue("4.2");
//        rPBean.setParamUnit("mg/l");
//
//        List list = new ArrayList();
//        for (int i = 0; i < 5; i++) {
//            RealDataEntity.ParamObjectListBean.RealtimeValuesBean bean = new RealDataEntity.ParamObjectListBean.RealtimeValuesBean();
//            bean.setDatetime(System.currentTimeMillis() + "");
//            bean.setStatus("1");
//            Random random = new Random();
//            float v = random.nextFloat();
//            int i1 = random.nextInt(9);
//            DecimalFormat format = new DecimalFormat("0.000");
//            bean.setParamValue((format.format(v) + i1) + "");
//            list.add(bean);
//        }
//        rPBean.setRealtimeValues(list);
//
//        List list2 = new ArrayList();
//        list2.add(rPBean);
//        entity.setParamObjectList(list2);

        Date date = new Date(2018, 6, 1);
        Calendar time = Calendar.getInstance();
        time.set(2018, 5, 1, 0, 0, 0);
        String yyyyMMddHHmmss = TimeUtils.date2String(time.getTime(), new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()));

        System.out.println("---------------------------yyyyMMddHHmmss:" + yyyyMMddHHmmss);
        Gson gson = new Gson();
        String s = gson.toJson(baseEntit);
        System.out.println("---------------------------");
        System.out.println(s);
        System.out.println((0 % 2) + "---------------------------" + (2 % 2));
        System.out.println((3 % 2) + "---------------------------");
        System.out.println('I' + 'T');
        System.out.println("3".compareTo("2.3"));
//        byte[] bytes = EncryptUtils.base64Decode(EncryptUtils.key.getBytes()); referenced
//        byte[] decode = Base64.decode(EncryptUtils.key.getBytes(), Base64.NO_WRAP);
//        String rsas1 = EncryptUtils.encryptRSA2HexString("123456".getBytes(), decode, false, "RSA");
//        System.out.println("rsas1---------------------------:" + rsas1);

        UserDao userdao= new UserDao();
        userdao.save();
    }




    public static class BaseDaoImpl<T> {
        private Class clazz;

        public BaseDaoImpl() {
//            ParameterizedType pt = (ParameterizedType) this.getClass()
//                    .getGenericSuperclass();
            this.clazz = getSuperClassGenricType(this.getClass(),0);
            System.out.println("Type为： " + clazz.getSimpleName());
        }
        public void save() {
            System.out.println("Type为： " + clazz.getSimpleName());
        }

        public static Class getSuperClassGenricType(Class clazz, int index) throws IndexOutOfBoundsException {

            Type genType = clazz.getGenericSuperclass();

            if (!(genType instanceof ParameterizedType)) {
                return Object.class;
            }

            Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

            if (index >= params.length || index < 0) {
                return Object.class;
            }
            if (!(params[index] instanceof Class)) {
                return Object.class;
            }
            return (Class) params[index];
        }

    }


    public static class UserDao extends BaseDaoImpl<UserDao>{

    }




}




